/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package humanNetwork;

import java.util.Arrays;
import java.util.HashMap;

/**
 *
 * @author jamie
 */
public class Edge implements Comparable{

    private final Node node1;
    private final Node node2;
    private InteractionType it;
    private final HashMap<String, Object> annots = new HashMap<String, Object>();
    private final String id;

    public Edge(Node n1, Node n2) {
        this.node1 = n1;
        this.node2 = n2;
        id = getNewId(n1, n2);
    }

    public void setInteractionType(InteractionType it) {
        this.it = it;
    }



    public String getId() {
        return id;
    }



    public Node getNode1() {
        return node1;
    }

    public Node getNode2() {
        return node2;
    }

    public void addAnnot(String key, Object annot){
        annots.put(key, annot);
    }

    public Object getAnnot(String key){
        return annots.get(key);
    }

    public InteractionType getInteractionType() {
        return it;
    }

    public HashMap<String, Object> getAnnots() {
        return annots;
    }


    @Override
    public boolean equals(Object other){
        if(other.getClass()!= this.getClass()){
            return false;
        }
        Edge otherEdge = (Edge) other;
        return otherEdge.getId().equals(this.id);
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 71 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    private String getNewId(Node n1, Node n2) {
        int[] ids = {n1.getId(), n2.getId()};
        Arrays.sort(ids);
        return ids[0]+":"+ids[1];
    }

    public int compareTo(Object o) {
        return this.getId().compareTo(((Edge)o).getId());
    }


}
